package com.ssm.reactive.controller;

import com.ssm.reactive.domain.Employee;
import com.ssm.reactive.service.EmployeeService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

@RestController
@RequiredArgsConstructor
@RequestMapping("employee")
public class EmployeeRestController {
    final EmployeeService employeeService;

    @GetMapping("{id}")
    public Mono<Employee> get(@PathVariable("id") Long id) {
        return employeeService.findById(id);
    }

    @GetMapping()
    public Flux<Employee> list() {
        return employeeService.findAll();
    }

    @PostMapping()
    public Mono<Employee> save(@RequestBody Employee employee) {
        return employeeService.save(employee);
    }

    @PutMapping()
    public Mono<Employee> update(@RequestBody Employee employee) {
        return employeeService.update(employee);
    }

    @DeleteMapping("{id}")
    public Mono<Void> delete(@PathVariable("id") Long id) {
        return employeeService.deleteById(id);
    }
}
